x86/hpet: simplify hpet_get_channel()
authorJan Beulich <jbeulich@suse.com>
Fri, 23 Mar 2012 15:13:29 +0000 (16:13 +0100)
committerJan Beulich <jbeulich@suse.com>
Fri, 23 Mar 2012 15:13:29 +0000 (16:13 +0100)
There's no need for a lock here, elimination of which makes the
function a leaf one, thus allowing for better (and smaller) code.

Further, use the variable next_channel according to its name - so far
it represented the most recently used channel rather than the next one
to use.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Keir Fraser <keir@xen.org>
xen/arch/x86/hpet.c

index b17cd07497e7d80febf693b25805da381eac2e1e..8ead34be607be951e949e6a4cb24fbb76ceacfba 100644 (file)
@@ -402,16 +402,17 @@ static void __init hpet_fsb_cap_lookup(void)
 static struct hpet_event_channel *hpet_get_channel(unsigned int cpu)
 {
     static unsigned int next_channel;
-    static spinlock_t next_lock = SPIN_LOCK_UNLOCKED;
     unsigned int i, next;
     struct hpet_event_channel *ch;
 
     if ( num_hpets_used == 0 )
         return hpet_events;
 
-    spin_lock(&next_lock);
-    next = next_channel = (next_channel + 1) % num_hpets_used;
-    spin_unlock(&next_lock);
+    do {
+        next = next_channel;
+        if ( (i = next + 1) == num_hpets_used )
+            i = 0;
+    } while ( cmpxchg(&next_channel, next, i) != next );
 
     /* try unused channel first */
     for ( i = next; i < next + num_hpets_used; i++ )